package com.book.service.impl;

import com.book.bean.User;
import com.book.dao.UserMapper;
import com.book.service.UserService;
import com.book.utils.MybatisUtil;
import jakarta.servlet.http.HttpSession;
import org.apache.ibatis.session.SqlSession;

public class UserServiceImpl implements UserService {
    @Override
    // 登录逻辑的实现
    public boolean auth(String username, String password, HttpSession session) {
        try (SqlSession sqlSession = MybatisUtil.getSqlSession()) {
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            User user = mapper.getUser(username, password);
            if(user == null) {
                return false;
            } else {
                session.setAttribute("user",user);
                return true;
            }


        }
    }
}
